﻿//
//
/////////////////////////////////////////////////////////////////////////////
using System;
using System.Windows;
using System.Windows.Input;
using ThinMediaLibrary;

/////////////////////////////////////////////////////////////////////////////
namespace ThinPlayer
{
    /////////////////////////////////////////////////////////////////////////
    public partial class MainWindow : Window
    {
        /////////////////////////////////////////////////////////////////////
        public MainWindow()
        {
            InitializeComponent();
            _initCommands();
        }

        /////////////////////////////////////////////////////////////////////
        private void _initCommands()
        {
            CommandBinding playBindingCommand = new CommandBinding(MediaCommands.Play);
            playBindingCommand.Executed += new ExecutedRoutedEventHandler(_executePlayCommand);
            this.CommandBindings.Add(playBindingCommand);

            CommandBinding previousTrackBindingCommand = new CommandBinding(MediaCommands.PreviousTrack);
            previousTrackBindingCommand.Executed += new ExecutedRoutedEventHandler(_executePreviousTrackCommand);
            this.CommandBindings.Add(previousTrackBindingCommand);

            CommandBinding stopTrackBindingCommand = new CommandBinding(MediaCommands.Stop);
            stopTrackBindingCommand.Executed += new ExecutedRoutedEventHandler(_executeStopCommand);
            this.CommandBindings.Add(stopTrackBindingCommand);

            CommandBinding nextTrackTrackBindingCommand = new CommandBinding(MediaCommands.NextTrack);
            nextTrackTrackBindingCommand.Executed += new ExecutedRoutedEventHandler(_executeNextTrackCommand);
            this.CommandBindings.Add(nextTrackTrackBindingCommand);
        }

        /////////////////////////////////////////////////////////////////////
        private void _executePreviousTrackCommand(object sender, ExecutedRoutedEventArgs e)
        {
            PlayListMediaItem mediaItem  = playListControl.SelectPreviousTrack();
            playControl.Play(mediaItem);
        }

        /////////////////////////////////////////////////////////////////////
        private void _executeNextTrackCommand(object sender, ExecutedRoutedEventArgs e)
        {
            PlayListMediaItem mediaItem = playListControl.SelectNextTrack();
            playControl.Play(mediaItem);
        }

        /////////////////////////////////////////////////////////////////////
        private void _executePlayCommand(object sender, ExecutedRoutedEventArgs e)
        {
            PlayListMediaItem mediaItem = e.Parameter as PlayListMediaItem;
            if (mediaItem == null)
            {
                mediaItem = playListControl.GetSelectedTrack();
            }
            playControl.Play(mediaItem);
        }

        /////////////////////////////////////////////////////////////////////
        private void _executeStopCommand(object sender, ExecutedRoutedEventArgs e)
        {
            playControl.Stop();
        }

        /////////////////////////////////////////////////////////////////////
        protected PlayListMediaCollection PlayList
        {
            get { return playListControl.PlayList; }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            
        }

        /////////////////////////////////////////////////////////////////////
        private void CloseCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            this.Close();
        }
    }
/////////////////////////////////////////////////////////////////////////////
}//ThinPlayer
